﻿using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;

public static class GUITheme
{
    public static Color DefaultColor { get; private set; }
    public static Color AcceptColor { get; private set; }
    public static Color WarningColor { get; private set; }
    public static Color ErrorColor { get; private set; }
    public static GUIStyle TitleStyle { get; private set; }
    public static GUIStyle ListItemHeaderStyle { get; private set; }
    public static GUIStyle IconButtonStyle { get; private set; }
    public static GUIStyle IconToolbarStyle { get; private set; }
    public static GUIStyle ActionButtonStyle { get; private set; }
    public static GUIStyle ColorLabelStyle { get; private set; }
    public static GUIStyle DragBarStyle { get; private set; }
    public static GUIStyle LabelTitleStyle { get; private set; }
    public static GUIStyle ContainerStyle { get; private set; }
    public static GUIStyle FooterStyle { get; private set; }

    public static GUIStyle OverwriteTextFieldStyle { get; private set; }

    public static GUIStyle OverwritePopupStyle { get; private set; }

    public static GUIStyle OverwriteToggleStyle { get; private set; }

    public static Texture2D TitleBackground { get; private set; }

    public static Texture2D ContainerBackground { get; private set; }

    static GUITheme()
    {
        GUITheme.DefaultColor = Color.white;
        GUITheme.AcceptColor = Color.green;
        GUITheme.WarningColor = Color.yellow;
        GUITheme.ErrorColor = Color.red;
        GUITheme.TitleStyle = new GUIStyle
        {
            border = new RectOffset(2, 2, 2, 1),
            margin = new RectOffset(5, 5, 5, 0),
            padding = new RectOffset(5, 5, 3, 3),
            alignment = TextAnchor.MiddleLeft
        };


        GUITheme.TitleStyle.normal.textColor = ((!EditorGUIUtility.isProSkin) ? new Color(0.2f, 0.2f, 0.2f) : new Color(0.8f, 0.8f, 0.8f));
        GUITheme.ListItemHeaderStyle = new GUIStyle
        {
            border = new RectOffset(2, 2, 2, 1),
            margin = new RectOffset(5, 5, 5, 0),
            padding = new RectOffset(5, 5, 0, 0),
            alignment = TextAnchor.MiddleLeft
        };

        GUITheme.ListItemHeaderStyle.normal.textColor = ((!EditorGUIUtility.isProSkin) ? new Color(0.2f, 0.2f, 0.2f) : new Color(0.8f, 0.8f, 0.8f));
        GUITheme.IconButtonStyle = new GUIStyle(GUI.skin.button)
        {
            stretchWidth = false,
            fixedHeight = 20f,
            margin = new RectOffset(5, 5, 0, 0),
            //font = GUITheme.FontAwesome,
            fontSize = 10,
            alignment = TextAnchor.MiddleCenter
        };

        GUITheme.IconButtonStyle.normal.background = null;
        GUITheme.IconToolbarStyle = new GUIStyle(GUI.skin.label)
        {
            stretchWidth = false,
            fixedHeight = 20f,
            border = new RectOffset(8, 8, 4, 4),
            padding = new RectOffset(4, 4, 2, 2),
            //font = GUITheme.FontAwesome,
            fontSize = 12,
            alignment = TextAnchor.MiddleCenter
        };

        GUITheme.IconToolbarStyle.active.background = GUI.skin.button.active.background;
        GUITheme.IconToolbarStyle.focused.background = GUI.skin.button.focused.background;
        GUITheme.IconToolbarStyle.hover.background = GUI.skin.button.hover.background;
        GUITheme.IconToolbarStyle.normal.background = GUI.skin.button.normal.background;
        GUITheme.IconToolbarStyle.onActive.background = GUI.skin.button.onActive.background;
        GUITheme.IconToolbarStyle.onFocused.background = GUI.skin.button.onFocused.background;
        GUITheme.IconToolbarStyle.onHover.background = GUI.skin.button.onHover.background;
        GUITheme.IconToolbarStyle.onNormal.background = GUI.skin.button.onNormal.background;
        GUITheme.ActionButtonStyle = new GUIStyle(GUI.skin.button)
        {
            fixedHeight = 20f,
            margin = new RectOffset(50, 50, 10, 0)
        };

        GUITheme.ColorLabelStyle = new GUIStyle(GUI.skin.label)
        {
            padding = new RectOffset(0, 0, 0, 0),
            margin = new RectOffset(0, 0, 0, 0),
            border = new RectOffset(0, 0, 0, 0),
            alignment = TextAnchor.MiddleCenter
        };

        GUITheme.ColorLabelStyle.normal.background = Texture2D.whiteTexture;
        GUITheme.DragBarStyle = new GUIStyle(GUI.skin.label)
        {
            stretchWidth = false,
            fixedHeight = 20f,
            padding = new RectOffset(7, 7, 2, 2),
            margin = new RectOffset(0, 0, 0, 0),
            border = new RectOffset(0, 0, 0, 0),
            //font = GUITheme.FontAwesome,
            fontSize = 10,
            alignment = TextAnchor.MiddleCenter
        };


        GUITheme.LabelTitleStyle = new GUIStyle(GUI.skin.label)
        {
            fontSize = 18,
            alignment = TextAnchor.MiddleCenter,
            padding = new RectOffset(0, 0, 0, 0)
        };
        GUITheme.ContainerStyle = new GUIStyle(GUI.skin.textArea)
        {
            margin = new RectOffset(5, 5, 0, 0),
            border = new RectOffset(2, 2, 2, 2),
            padding = new RectOffset(2, 2, 2, 2)
        };

        GUITheme.FooterStyle = new GUIStyle
        {
            margin = new RectOffset(0, 0, 0, 0),
            border = new RectOffset(0, 0, 0, 0),
            padding = new RectOffset(0, 0, 0, 0)
        };
        GUITheme.OverwriteTextFieldStyle = new GUIStyle(EditorStyles.textField);
        GUITheme.OverwriteTextFieldStyle.fontStyle = FontStyle.Bold;
        GUITheme.OverwritePopupStyle = new GUIStyle(EditorStyles.popup);
        GUITheme.OverwritePopupStyle.fontStyle = FontStyle.Bold;
        GUITheme.OverwriteToggleStyle = new GUIStyle(EditorStyles.toggle);
        GUITheme.OverwriteToggleStyle.fontStyle = FontStyle.Bold;

    }
}
